import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/10 20:05
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 2, 3, 4, 0}, index = {0, 1, 2, 3, 0};
        solution.createTargetArray(nums, index);
    }
    public int[] createTargetArray(int[] nums, int[] index) {
        int n = nums.length;
        int[] res = new int[n];
        Arrays.fill(res, -1);
        for (int i = 0; i < n; i++) {
            if (res[index[i]] == -1) {
                res[index[i]] = nums[i];
                continue;
            }
            for (int j = i ; j > index[i]; j--) {
                res[j] = res[j-1];
            }
            res[index[i]] = nums[i];
        }
        return res;
    }
}
